.Net: feat(connectors): Support ImageContent in tool/function results#13431
Open
Cozmopolit wants to merge 4 commits intomicrosoft:mainfrom
Open
.Net: feat(connectors): Support ImageContent in tool/function results#13431Cozmopolit wants to merge 4 commits intomicrosoft:mainfrom
Cozmopolit wants to merge 4 commits intomicrosoft:mainfrom
Conversation
Enable ImageContent preservation in function results for multimodal-capable connectors (Gemini 3+). Non-supporting connectors return clear error message. Changes: - FunctionCallsProcessor: Return object instead of string, preserve ImageContent - Gemini: Native support via FunctionResponse.Parts with inlineData - OpenAI/Bedrock Agents: Error handling with ImageContentNotSupportedErrorMessage Includes 5 new unit tests for ImageContent handling. Fixes microsoft#13430
Member
|
@Cozmopolit Thanks for the contribution! With the latest merges into the Google connector this PR is now with a conflict, appreciate if you can take a look. |
Contributor
Author
|
Done, test file conflict resolved. |
markwallace-microsoft
approved these changes
Jan 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation and Context
Fixes #13430
Currently, when a Semantic Kernel function returns
ImageContent, it gets serialized to JSON - losing the binary image data and preventing multimodal-capable models from processing the image.This PR enables
ImageContentpreservation in tool/function results, allowing connectors with multimodal capabilities (Gemini 3+, Anthropic) to pass images natively to the model. This is essential for agentic workflows where tools generate or process images that the model needs to analyze.Description
FunctionCallsProcessor (shared infrastructure)
ProcessFunctionResult()return type fromstringtoobjectImageContentto preserve it for multimodal-capable connectorsImageContentNotSupportedErrorMessageconstant for consistent error messagingGoogle Gemini Connector (native support)
FunctionResponsePartwithPartsproperty for nested multimodal contentFunctionResponsePartContentclass withInlineDatasupportCreateImageFunctionResponsePart()to convertImageContentto Gemini's nativeinlineDataformatOpenAI Connector (error handling)
ImageContentcheck with clear error message (API does not support images in tool results)OpenAI Agents (error handling)
GetFunctionResultAsString()helper withImageContenterror handlingAmazon Bedrock Agents (error handling)
GetFunctionResultAsString()helper withImageContenterror handlingNew Unit Tests
ItShouldPreserveImageContentWithoutSerializationFunctionCallsProcessorTests.csFromChatHistoryImageContentInToolResultCreatesInlineDataPartGeminiRequestTests.csFromChatHistoryImageContentWithoutDataThrowsInvalidOperationExceptionGeminiRequestTests.csFromChatHistoryImageContentWithoutMimeTypeThrowsInvalidOperationExceptionGeminiRequestTests.csVerifyAssistantMessageAdapterGetMessageWithImageContentInFunctionResultAssistantMessageFactoryTests.csNotes
FunctionResultContent.Resultproperty is alreadyobject?.functionResponse.parts, the API will return an appropriate error.ImageContentwith binary data is supported. URI-basedImageContentwill throwInvalidOperationException.ProcessFunctionResultimplementation.Contribution Checklist
sk-pr-MultimodalToolResults.md